package homework;

import java.util.ArrayList;
import java.util.Objects;

public class Test08_StudentManagement {
    public static void main(String[] args) {
        Student s1 = new Student("111","张三",
                "大数据1班");
        Student s2 = new Student("112","李四",
                "大数据1班");
        Student s3 = new Student("113","王五",
                "大数据1班");
        Student s4 = new Student("114","赵六",
                "大数据1班");
        StudentManagement smant = new StudentManagement();
        smant.addStudent(s1);
        smant.addStudent(s2);
        smant.addStudent(s3);
        smant.addStudent(s4);
        smant.output();
        Student s5 = new Student("111","张三",
                "大数据1班");
        System.out.println(smant.checkStudent(s5));
        System.out.println(smant.deleteStudent(s5));
        smant.output();
    }
}
class Student{
    private String id;
    private String name;
    private String grade;
    public Student(String id, String name, String grade) {
        this.id = id;
        this.name = name;
        this.grade = grade;
    }
    public String toString() {
        return id+":"+name+":"+grade;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass())
            return false;
        Student student = (Student) o;
        return id.equals(student.id);
    }
    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
class StudentManagement{
    private ArrayList<Student> slist;
    //增加
    public void addStudent(Student s){
        slist.add(s);
        System.out.println("增加成功");
    }
    //查找
    public boolean checkStudent(Student s){
        for(Student s1:slist){
            if(s1.equals(s)){
                return true;
            }
        }
        return false;
    }
    //删除
    public boolean deleteStudent(Student s){
        if(checkStudent(s)){
            slist.remove(s);
            return true;
        }
        return false;
    }
    public void output(){
        for (Student s:slist) {
            System.out.println(s);
        }
    }
    public int getNumber(){
        return slist.size();
    }
    public StudentManagement(){
        slist = new ArrayList<>();
    }
}
